/*
 * @Author: your name
 * @Date: 2021-06-03 11:22:06
 * @LastEditTime: 2021-06-03 14:28:23
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \bazai_island_api\app\api\v1\like.js
 */
const Router = require('koa-router')
const router = new Router()

router.prefix('/v1/like')

const { Auth } = require('@middlewares/auth')
const { LikeValidator } = require('../../validators/validators')
const { Favor } = require('@models/favor')
const { success } = require('../../lib/helper')

router.post('/', new Auth().m, async(ctx)=> {
    const v = await new LikeValidator().validate(ctx, {
        id: 'art_id'
    })

    await Favor.like(
        v.get('body.art_id'), v.get('body.type'),
        ctx.auth.uid
    )
    success()
})

router.post('/cancel', new Auth().m, async(ctx)=> {
    const v = await new LikeValidator().validate(ctx, {
        id: 'art_id'
    })

    await Favor.disLike(
        v.get('body.art_id'), v.get('body.type'),
        ctx.auth.uid
    )
    success()
})

module.exports = router
